#coding=utf-8
import time, threading

# 新线程执行的代码:
def loop():
    print 'thread %s is running...' % threading.current_thread().name
    n = 0
    while n < 10:
        n = n + 1
        print 'thread %s >>> %s' % (threading.current_thread().name, n)
        time.sleep(1)
    print 'thread %s ended.' % threading.current_thread().name

def loop2():
    a = 1
    while True:
        a=a*2

print 'thread %s is running...' % threading.current_thread().name
t = threading.Thread(target=loop2, name='LoopThread')
t.start()
t.join()
print 'thread %s ended.' % threading.current_thread().name




import threading, multiprocessing

def loop():
    x = 0
    while True:
        x = x ^ 1

for i in range(multiprocessing.cpu_count()):
    t = threading.Thread(target=loop)
    t.start()